<html>

<head>
<style>
.tabtop13 {
	margin-top: 13px;
}
.tabtop13 td{
	background-color:#ffffff;
	height:25px;
	line-height:150%;
}
.font-center{ text-align:center}
.btbg{background:#e9faff !important;}
.btbg1{background:#f2fbfe !important;}
.btbg2{background:#f3f3f3 !important;}
.btbg3{background:#f1f7fa !important;}
.biaoti{
	font-family: 微软雅黑;
	font-size: 26px;
	font-weight: bold;
	border-bottom:1px dashed #CCCCCC;
	color: #255e95;
}
.titfont {
	
	font-family: 微软雅黑;
	font-size: 16px;
	font-weight: bold;
	color: #255e95;
	background: url(../images/ico3.gif) no-repeat 15px center;
	background-color:#e9faff;
}
.tabtxt2 {
	font-family: 微软雅黑;
	font-size: 14px;
	font-weight: bold;
	text-align: right;
	padding-right: 10px;
	color:#327cd1;
}
.tabtxt3 {
	font-family: 微软雅黑;
	font-size: 14px;
	padding-left: 15px;
	color: #000;
	margin-top: 10px;
	margin-bottom: 10px;
	line-height: 20px;
}

</style>

</head>

<body>

    <div><span>全局倍率(AutoBalance.rate.global)：</span><input id="globalRate"/></div>
    <div><span>基础血量倍率(AutoBalance.rate.health )：</span><input id="healthRate"/></div>
    <div><span>基础伤害倍率(AutoBalance.rate.damage)：</span><input id="damageRate"/></div>
    <div><span>最小血量倍率(AutoBalance.MinHPModifier)：</span><input id="minHPModifier"/></div>
    <div><span>最小伤害倍率(AutoBalance.MinDamageModifier)：</span><input id="minDamageModifier"/></div>
    <div><span>5人弹性拐点(AutoBalance.InflectionPoint)：</span><input id="iflectionPoint"/></div>
    <div><span>10人弹性拐点(AutoBalance.InflectionPointRaid10M)：</span><input id="InflectionPointRaid10M"/></div>
    <div><span>25人弹性拐点(AutoBalance.InflectionPointRaid25M)：</span><input id="inflectionPointRaid25M"/></div>
    <div><span>boss弹性拐点独立倍率(AutoBalance.BossInflectionMult)：</span><input id="bossInflectionMult"/></div>
    <div><input type="button" value="提交" onclick="submit()"/></div>

    <div id="simulation5M"> </div>
    <div id="simulation10M"> </div>
    <div id="simulation25M"> </div>

    <div align="center"><span>@CopyRight StephZcj</span></div>
    <div  align="center"><span>Version: 1.1.0</span></div>

    <script type="text/javascript">
        //configurations from AutoBalance.conf
        //AutoBalance.rate.health 
        var healthRate = 1.1;
        //AutoBalance.rate.damage
        var damageRate = 1;
        //AutoBalance.rate.global
        var globalRate = 1.1;
        //AutoBalance.MinDamageModifier
        var minDamageModifier = 0.4;
        //AutoBalance.MinHPModifier
        var minHPModifier = 0.7;
        //AutoBalance.InflectionPoint
        var iflectionPoint = 0.6;
        //AutoBalance.InflectionPointRaid10M
        var InflectionPointRaid10M = 0.6;
        //AutoBalance.InflectionPointRaid25M
        var inflectionPointRaid25M = 0.6;
        //AutoBalance.BossInflectionMult
        var bossInflectionMult = 0.8;

        window.onload = function(){
            document.getElementById("globalRate").value = globalRate;
            document.getElementById("healthRate").value = healthRate;
            document.getElementById("damageRate").value = damageRate;
            document.getElementById("minDamageModifier").value = minDamageModifier;
            document.getElementById("minHPModifier").value = minHPModifier;
            document.getElementById("iflectionPoint").value = iflectionPoint;
            document.getElementById("InflectionPointRaid10M").value = InflectionPointRaid10M;
            document.getElementById("inflectionPointRaid25M").value = inflectionPointRaid25M;
            document.getElementById("bossInflectionMult").value = bossInflectionMult;
            submit()
        }

        function submit(){
            globalRate = Number(document.getElementById("globalRate").value) ;
            healthRate = Number(document.getElementById("healthRate").value) ;
            damageRate = Number(document.getElementById("damageRate").value) ;
            minDamageModifier = Number(document.getElementById("minDamageModifier").value) ;
            minHPModifier = Number(document.getElementById("minHPModifier").value) ;
            iflectionPoint = Number(document.getElementById("iflectionPoint").value) ;
            InflectionPointRaid10M = Number(document.getElementById("InflectionPointRaid10M").value) ;
            inflectionPointRaid25M = Number(document.getElementById("inflectionPointRaid25M").value) ;
            bossInflectionMult = Number(document.getElementById("bossInflectionMult").value) ;

            renderTable(iflectionPoint,5,"simulation5M",healthRate,minHPModifier);
            renderTable(InflectionPointRaid10M,10,"simulation10M",healthRate,minHPModifier);
            renderTable(inflectionPointRaid25M,25,"simulation25M",healthRate,minHPModifier);
        }

        /**
         * 渲染表格
         */
        function renderTable(InflectionPoint, maxPlayers, elementId, minMultipiler){
            let finalHtml = '';
            finalHtml += '<table width="100%" border="0" cellspacing="1" cellpadding="4" bgcolor="#cccccc" class="tabtop13" align="center">'
            + getTableHeaderL1(maxPlayers) + getTableHeaderL2() + getTableHeaderL3();
            for(let realPlayer=1;realPlayer<=maxPlayers;realPlayer++){
                let ABMultiplier = getAutoBalancedMultipiler(InflectionPoint, maxPlayers, realPlayer);
                let realHpMultipiler = getFinalMultipiler(InflectionPoint,maxPlayers,realPlayer,healthRate,minHPModifier);
                let realDmgMultipiler = getFinalMultipiler(InflectionPoint,maxPlayers,realPlayer,damageRate,minDamageModifier);
                let realHpBossMultipiler = getFinalMultipiler(InflectionPoint,maxPlayers,realPlayer,healthRate,minHPModifier,true);
                let realDmgBossMultipiler = getFinalMultipiler(InflectionPoint,maxPlayers,realPlayer,damageRate,minDamageModifier,true);
                finalHtml += '<tr align="center">'
                    +'<td class="btbg3">'+realPlayer+'</td>'//人数
                    +'<td class="btbg3">'+ABMultiplier.toFixed(3)+'</td>'//血量弹性倍率
                    +'<td class="btbg3">'+realHpMultipiler.toFixed(3)+'</td>'//血量综合倍率
                    +'<td class="btbg">'+realHpBossMultipiler.toFixed(3)+'</td>'//血量BOSS倍率
                    +'<td class="btbg3">'+ABMultiplier.toFixed(3)+'</td>'//伤害弹性倍率
                    +'<td class="btbg3">'+realDmgMultipiler.toFixed(3)+'</td>'//伤害综合倍率
                    +'<td class="btbg">'+realDmgBossMultipiler.toFixed(3)+'</td>'//伤害BOSS倍率
                    +'</tr>';
            }
            finalHtml += '</table>';
            document.getElementById(elementId).innerHTML = finalHtml;
        }      

        /**
         * 获取最终倍率
         * @param InflectionPoint 
         * @param maxPlayers
         * @param currPlayers
         * @param confBaseMultipiler
         * @param minMultipiler
         */
        function getFinalMultipiler(InflectionPoint, maxPlayers, currPlayers, confBaseMultipiler, minMultipiler, isBoss){
            let defaultMultiplier = getAutoBalancedMultipiler(InflectionPoint, maxPlayers, currPlayers, isBoss);
            //最终公式是 配置的基础倍率*弹性倍率*全局倍率
            let realMultipiler = confBaseMultipiler * defaultMultiplier * globalRate;
            if (realMultipiler < minMultipiler){
                realMultipiler = minMultipiler;
            }
            return realMultipiler;
        }

        /**
         * 获取弹性倍率
         * @param InflectionPoint 
         * @param maxPlayers
         * @param currPlayers
         * @param isBoss
         */
        function getAutoBalancedMultipiler(InflectionPoint, maxPlayers, currPlayers, isBoss){
            let InflectionValue = InflectionPoint * maxPlayers;
            if(isBoss){
                InflectionValue *= bossInflectionMult;
            }
            let diff = maxPlayers/5*1.5;
            //tanh的参数越小，返回的值越小，但不同点位速率不同（返回值越靠近1的地方，切线斜率越陡，表示参数只需变动一点点即可获得较大变动的返回值）
            //这里通过InflectionValue来控制，值越大，则说明队伍里只需减少一两个的玩家就能获得高额的数值减免
            let tanhParam = (currPlayers - InflectionValue)/diff;
            //这里+1和/2是为了把tanh取值范围控制在[0,1]
            let defaultMultiplier = (Math.tanh(tanhParam) + 1)/2;
            return defaultMultiplier;
        }

        function getTableHeaderL1(maxPlayers){
            return '<tr class="btbg font-center titfont"><th colspan="7">'+maxPlayers+'人弹性模拟（全局倍率：'+globalRate.toFixed(3)+'）</th></tr>';
        }

        function getTableHeaderL2(){
            return '<tr class="btbg font-center titfont" align="center">'
                +'<th rowspan="2">人数</th>'
                +'<th colspan="3">Health（基础倍率：'+healthRate.toFixed(3)+'，倍率下限'+minHPModifier.toFixed(3)+'）</th>'
                +'<th colspan="3">Damage（基础倍率：'+damageRate.toFixed(3)+'，倍率下限'+minDamageModifier.toFixed(3)+'）</th>'
                +'</tr>';
        }

        function getTableHeaderL3(){
            return '<tr class="btbg font-center titfont" align="center">'
                +'<th>弹性倍率</th><th>生物综合倍率</th><th>BOSS综合倍率</th>'
                +'<th>弹性倍率</th><th>生物综合倍率</th><th>BOSS综合倍率</th>'
                +'</tr>';
        }

        

    </script>

</body>







</html>